<template>
  <div>
    home
    <el-button @click="openDialog">按钮</el-button>
    <el-dialog
        v-model="dialogVisible"
        title="Tips"
        width="30%"
        :before-close="handleClose"
    >
      <span>This is a message</span>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="add"
        >Confirm</el-button
        >
      </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>


import {ElMessageBox} from "element-plus";
import request from "../utils/request";

export default {
  name: 'Home',
  components: {

  },
  data() {
    return {
      dialogVisible: false,
      form: {
        username: 'jack',
        password: '123456'
      }
    }
  },methods: {
    add(){
      this.form = {
        username: 'jack112',
      }
      console.log('test')
      request.post("/api/user",this.form).then(res => {
        console.log(res)
        if (res.code === 0) {
          this.$message({
            type:"success",
            message:"添加成功"
          })
        } else {
          this.$message({
            type:"error",
            message:"添加失败"
          })
        }

      })
    },
    openDialog() {
      this.dialogVisible = true
      //this.form = {}
    },
    handleClose(){
      ElMessageBox.confirm('确定关闭?')
    }
  }
}
</script>
